const moment = require('moment')

module.exports = (sequelize,DataTypes) => {
  return sequelize.define('user', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      autoIncrement: true,
      primaryKey: true
    },
    nickname: {
      type: DataTypes.STRING,
      allowNull: false,
      field: 'nickname'
    },
    password: {
      type:DataTypes.STRING,
      allowNull: false,
      field: 'password'
    },
    email: {
      type: DataTypes.STRING,
      allowNull: false,
      field: 'email'
    },
    avator: {
      type: DataTypes.STRING,
      allowNull: true,
      field: 'avator'
    },
    gender: {
      type: DataTypes.INTEGER,
      allowNull: true,
      field: 'gender'
    },
    desc: {
      type: DataTypes.STRING,
      allowNull: true,
      field: 'desc'
    },
    status: {
      type: DataTypes.INTEGER,
      allowNull: false,
      default: 1,
      field: 'status'
    },
    createAt: {
      type: DataTypes.DATE,
      get(){
        return moment(this.getDataValue('createAt')).format('YYYY-MM-DD HH:mm:ss')
      }
    },
    updateAt: {
      type: DataTypes.DATE,
      get(){
        return moment(this.getDataValue('updateAt')).format('YYYY-MM-DD HH:mm:ss')
      }
    }
  },{
    freezeTableName: true,
    timestamps: false
  })
}